package com.example.springboot1.controller;

import com.example.springboot1.Service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/score/oss")
public class ServiceOssController {
    @Autowired
    private OssService ossService;
    @PostMapping("/uposs")
    public String upOssFile(MultipartFile file){
        if (file.getSize() > 1024*1024*5) {
            return "图片大小不能大于5M";
        }
        String fix=file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
        if (!"jpg,jpeg,gif,png".toUpperCase().contains(fix.toUpperCase())){
            return "请选择jpg,jpeg,gif,png格式的图片";
        }
        String url = ossService.getFileUrl(file);
        return url;
    }

//    @PostMapping("/deloss")
//    public R delOssFile(@RequestBody String ingName){
////        System.out.println(ingName);
//        boolean url = ossService.delete(ingName);
//        if (url){
//            return R.ok().data("url",url);
//        }else {
//            return R.error().message("失败");
//        }
//
//    }
}
